/*
 * News.java
 *
 * Created on 25 wrzesień 2007, 23:14
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.db;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class News
 * 
 * @author Krystian
 */
@Entity
@Table(name = "NEWS")
@NamedQueries( {
        @NamedQuery(name = "News.findByNwsId", query = "SELECT n FROM News n WHERE n.nwsId = :nwsId"),
        @NamedQuery(name = "News.findByNwsTitle", query = "SELECT n FROM News n WHERE n.nwsTitle = :nwsTitle"),
        @NamedQuery(name = "News.findByNwsUsrId", query = "SELECT n FROM News n WHERE n.user = :iser"),
        @NamedQuery(name = "News.findByNwsHeader", query = "SELECT n FROM News n WHERE n.nwsHeader = :nwsHeader")
    })
public class News implements Serializable {

    @Id
    @Column(name = "NWS_ID", nullable = false)
    private Integer nwsId;

    @Column(name = "NWS_TITLE", nullable = false)
    private String nwsTitle;

    @Column(name = "NWS_HEADER", nullable = false)
    private String nwsHeader;
    
    @Column(name = "NWS_DATE", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date nwsDate;

    @Lob
    @Column(name = "NWS_BODY")
    private String nwsBody;

    @JoinColumn(name = "NWS_USR_ID", referencedColumnName = "USR_ID")
    @ManyToOne
    private Users user;
    
    /** Creates a new instance of News */
    public News() {
    }

    /**
     * Creates a new instance of News with the specified values.
     * @param nwsId the nwsId of the News
     */
    public News(Integer nwsId) {
        this.nwsId = nwsId;
    }


    public News(String nwsTitle, String nwsHeader, String nwsBody) {
        this.nwsTitle = nwsTitle;
        this.nwsHeader = nwsHeader;
        this.nwsBody = nwsBody;
    }

    /**
     * Gets the nwsId of this News.
     * @return the nwsId
     */
    public Integer getNwsId() {
        return this.nwsId;
    }

    /**
     * Sets the nwsId of this News to the specified value.
     * @param nwsId the new nwsId
     */
    public void setNwsId(Integer nwsId) {
        this.nwsId = nwsId;
    }

    /**
     * Gets the nwsTitle of this News.
     * @return the nwsTitle
     */
    public String getNwsTitle() {
        return this.nwsTitle;
    }

    /**
     * Sets the nwsTitle of this News to the specified value.
     * @param nwsTitle the new nwsTitle
     */
    public void setNwsTitle(String nwsTitle) {
        this.nwsTitle = nwsTitle;
    }

    /**
     * Gets the nwsHeader of this News.
     * @return the nwsHeader
     */
    public String getNwsHeader() {
        return this.nwsHeader;
    }

    /**
     * Sets the nwsHeader of this News to the specified value.
     * @param nwsHeader the new nwsHeader
     */
    public void setNwsHeader(String nwsHeader) {
        this.nwsHeader = nwsHeader;
    }

    /**
     * Gets the nwsBody of this News.
     * @return the nwsBody
     */
    public String getNwsBody() {
        return this.nwsBody;
    }

    /**
     * Sets the nwsBody of this News to the specified value.
     * @param nwsBody the new nwsBody
     */
    public void setNwsBody(String nwsBody) {
        this.nwsBody = nwsBody;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.nwsId != null ? this.nwsId.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this News.  The result is 
     * <code>true</code> if and only if the argument is not null and is a News object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof News)) {
            return false;
        }
        News other = (News)object;
        if (this.nwsId != other.nwsId && (this.nwsId == null || !this.nwsId.equals(other.nwsId))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "info.mikrotubula.db.News[nwsId=" + nwsId + "]";
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }
    
}
